package com.ib.review.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ib.review.base.response.JsonResult;
import com.ib.review.pojo.dto.BatchDeleteParam;
import com.ib.review.pojo.dto.KnowledgeParam;
import com.ib.review.pojo.dto.KnowledgeQuery;
import com.ib.review.pojo.po.KnowledgeBasePO;
import com.ib.review.service.KnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/review/knowledge")
public class KnowledgeController {

    private final KnowledgeService knowledgeService;
    @Autowired
    public KnowledgeController(KnowledgeService knowledgeService){
        this.knowledgeService = knowledgeService;
    }
    @GetMapping("query")
    public JsonResult<Page<KnowledgeBasePO>> query(KnowledgeQuery knowledgeQuery) {
        Page<KnowledgeBasePO> page = knowledgeService.query(knowledgeQuery);
        return JsonResult.ok(page);
    }
    @PostMapping("add")
    public JsonResult<Void> add(@RequestBody KnowledgeParam knowledgeParam) {
        knowledgeService.add(knowledgeParam);
        return JsonResult.ok();
    }
    @PostMapping("delete")
    public JsonResult<Void> delete(@RequestBody KnowledgeParam knowledgeParam) {
        knowledgeService.delete(knowledgeParam);
        return JsonResult.ok();
    }
    @PostMapping("edit")
    public JsonResult<Void> edit(@RequestBody KnowledgeParam knowledgeParam) {
        knowledgeService.edit(knowledgeParam);
        return JsonResult.ok();
    }
    @PostMapping("batchDelete")
    public JsonResult<Void> batchDelete(@RequestBody BatchDeleteParam batchDeleteParam) {
        knowledgeService.batchDelete(batchDeleteParam);
        return JsonResult.ok();
    }
    @PostMapping("importExcel")
    public JsonResult<Void> importExcel(@RequestParam("file") MultipartFile file) {
        knowledgeService.importExcel(file);
        return JsonResult.ok();
    }
}
